package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;

import com.quasar.hpatient.R;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.qrcode.ZXingUtil;

/**
 * description: 我 ==> 二维码
 * created by kalu on 2018/3/29 9:03
 */
public class QrcodeDialog extends BaseDialog {

    private Bitmap bitmap;
    private Bitmap qrCode;

    public QrcodeDialog(Activity activity) {
        super(activity);
    }

    @Override
    public void onBackPressed() {

        if (null != bitmap) {
            bitmap.recycle();
        }

        if (null != qrCode) {
            qrCode.recycle();
        }

        super.onBackPressed();
    }

    @Override
    public void dismiss() {

        if (null != bitmap) {
            bitmap.recycle();
        }

        if (null != qrCode) {
            qrCode.recycle();
        }

        super.dismiss();
    }

    @Override
    public void cancel() {

        if (null != bitmap) {
            bitmap.recycle();
        }

        if (null != qrCode) {
            qrCode.recycle();
        }

        super.cancel();
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_qrcode;
    }

    @Override
    protected void initData() {

        ImageView image = findViewById(R.id.fragment_mine_qrcode_dialog_image);
        if (null == image) return;

        bitmap = BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.ic_launcher);
        if (null == bitmap) return;
        qrCode = ZXingUtil.createQRCodeWithLogo("18791984289", bitmap);
        if (null == qrCode) return;
        image.setImageBitmap(qrCode);
    }
}
